package com.emergency.db.controller.staff;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.staff.StaffDose;
import com.emergency.db.service.staff.StaffDoseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/staff/dose")
@CrossOrigin
public class StaffDoseController {
    @Autowired
    private StaffDoseService staffDoseService;

    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody StaffDose staffDose) {
        Long id = staffDoseService.save(staffDose);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result del(@PathVariable("id") Long id) {
        staffDoseService.deleteAllByStaff(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    //分页
    @RequestMapping(value = "/list/{id}/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable Long id, @PathVariable int page, @PathVariable int size) {
        Page<StaffDose> pageList = staffDoseService.findList(searchMap, page, size, id);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
}
